#include "LookUp_S16_U32.h"
#include "BINARYSEARCH_U32.h"
#include "div_repeat_u32.h"
#include "mul_ssu32_loSR.h"
#include "rtwtypes.h"

void LookUp_S16_U32(int16_T *pY, const int16_T *pYData, uint32_T u, const
                    uint32_T *pUData, uint32_T iHi)
{
  uint32_T iLeft;
  uint32_T iRght;
  BINARYSEARCH_U32( &(iLeft), &(iRght), u, pUData, iHi);

  {
    uint32_T lambda;
    if (pUData[iRght] > pUData[iLeft] ) {
      uint32_T num;
      uint32_T den;
      den = pUData[iRght];
      den -= pUData[iLeft];
      num = u;
      num -= pUData[iLeft];
      lambda = div_repeat_u32(num, den, 31U);
    } else {
      lambda = 0U;
    }

    (*pY) = pYData[iRght];
    (*pY) -= pYData[iLeft];
    (*pY) = (int16_T)mul_ssu32_loSR((*pY), lambda, 31U);
    (*pY) += pYData[iLeft];
  }
}
